<?PHP
include_once "../../public/DB_Oracle.php";
$DBsql=new DB_Oracle();
if(isset($_POST['a'])){
	$sql="select * from dep_department t,dep_area t1 where t.area_index=t1.area_index and t1.area_name='".$_POST['a']."' and (t.department_name like '%".$_POST['text']."%' or t.pinyin like '%".$_POST['text']."%')";
	$arr=$DBsql->fetch_all_array($sql);
    if(count($arr)>0){
	for($i=0;$i<count($arr);++$i){
		if($i==(count($arr)-1)){
		echo $arr[$i]['DEPARTMENT_NAME'];	
			}else{
		echo $arr[$i]['DEPARTMENT_NAME']."_";
	}
	}
	}	
	exit();
	}
if(isset($_POST['text'])&&trim($_POST['text'])!=""){
$sql="select * from dep_area t where t.area_name like '%".$_POST['text']."%' or t.pinyin like '%".$_POST['text']."%'";
$arr=$DBsql->fetch_all_array($sql);
if(count($arr)>0){
	for($i=0;$i<count($arr);++$i){
		if($i==(count($arr)-1)){
		echo $arr[$i]['AREA_NAME'];	
			}else{
		echo $arr[$i]['AREA_NAME']."_";
	}
	}
	}
exit();
}
if(isset($_POST["v"])){
		$sql="select * from dep_time";
	$rowTime=$DBsql->fetch_one_array($sql);
		 $sql_for_vehicle_online = "select *
  from (select t.longitude,
               t.latitude,
               t.device_id,
               t.speed,
               t.angle,
               t.height,
               t.recv_time,
               v.vehicle_name,
               v.license_plate,
               v.sim,
               vt.vehicle_type_name,
               d.department_name,
               a.area_name
          from loc_vehicle_0101 t,
               dep_vehicle      v,
               dep_vehicle_type vt,
               dep_department   d,
               dep_area         a
         where t.device_id = v.device_id
           and v.vehicle_type_index = vt.vehicle_type_index
           and d.department_index = v.department_index
           and t.recv_time >sysdate-".$rowTime['TIME']."/(24*3600)
           and t.recv_time <sysdate
           and a.area_index = d.area_index) a,
       (select max(t.recv_time) time, t.device_id
          from loc_vehicle_0101 t
         where t.recv_time >sysdate-60/(24*3600)
           and t.recv_time <sysdate
         group by t.device_id) b
 where a.recv_time = b.time
   and a.device_id = b.device_id";
	$AllVehicleArr = $DBsql->fetch_all_array($sql_for_vehicle_online);
	if(count($AllVehicleArr)>0){
		echo count($AllVehicleArr);
	}else{
		echo 0;
		}
		exit();
	}
?>